package interfaces;

import datastructures.Vector2f;
import exceptions.Exception;
import gameclasses.GameManager;
import helperclasses.IDGenerator;


public abstract class IBuilding implements IHitable {

	protected GameManager gm;
	protected final int playerID;
	protected Vector2f position;
	protected final int maxHitPoints;
	protected int hitPoints;
	protected final int price;
	protected final long ID;
	protected int buildtime;

	protected IBuilding(GameManager gm, int playerID, Vector2f position,
			int maxHitPoints, int hitPoints, int price, int ID, int buildtime) {
		this.gm = gm;
		this.playerID = playerID;
		this.position = position;
		this.maxHitPoints = maxHitPoints;
		this.hitPoints = hitPoints;
		this.price = price;
		this.ID = IDGenerator.getID();
		this.buildtime = buildtime;
	}

	@Override
	public int getHitPoints() {
		return hitPoints;
	}

	@Override
	public int hit(int attackpoints){
		hitPoints -= attackpoints;

		if (hitPoints < 0) {
			gm.removeBuilding(this);
			return Exception.TARGET_DESTROYED;
		}
		return Exception.TARGET_HIT;

	}

	@Override
	public int repair(int amount){
		hitPoints = maxHitPoints;
		return 0; //TODO reparierte punkte zur�ckgeben
	}

	@Override
	public Vector2f getPosition(){
		return position;
	}
	

	public long getID() {
		return ID;
	}

}
